﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DA
{
    public class danhsachlop_DA
    {
        DataLINQHocSinhDataContext dt = new DataLINQHocSinhDataContext();
        public object layalllophoc()
        {
            return dt.LOPs.ToList();
        }

        public object laytheomk(string mk)
        {
            return dt.LOPs.Where(p => p.MAKHOI == mk).ToList();
        }

        public object laytheoml(string ml)
        {
            return dt.LOPs.Where(p => p.MALOP == ml).ToList();
        }

        public bool ktralophoc(LOP lh)
        {
            var query = from p in dt.LOPs
                        where p.MALOP == lh.MALOP
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }

        public bool ktrasiso(int qd)
        {
            var query = from p in dt.LOPs
                        where p.SISO > qd
                        select p;
            if (query.Count() != 0)
            {
                return true;
            }
            return false;
        }
        public void themlophoc(LOP lh)
        {
            LOP a = new LOP();
            a.MALOP = lh.MALOP;
            a.TENLOP = lh.TENLOP;
            a.SISO = lh.SISO;
            a.MAGV = lh.MAGV;
            a.MAKHOI = lh.MAKHOI;

            dt.LOPs.InsertOnSubmit(a);
            dt.SubmitChanges();
        }
        public void xoalophoc(LOP lh)
        {
            var query = from p in dt.LOPs
                        where p.MALOP == lh.MALOP
                        select p;
            dt.LOPs.DeleteAllOnSubmit(query);
            dt.SubmitChanges();
        }
    }
}
